<!DOCTYPE html>
<html class="x-admin-sm">
    <head>
        <meta charset="UTF-8">
        <title>欢迎页面-X-admin2.2</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="../../static/css/font.css">
        <link rel="stylesheet" href="../../static/css/xadmin.css">
        <script src="../../static/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="../../static/js/xadmin.js"></script>
        <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>
        <div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="#">首页</a>
            <a href="#">服务器管理</a>
            <a>
              <cite>服务器部署</cite></a>
          </span>
          <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <form class="layui-form layui-col-space5">
                                <div class="layui-input-inline layui-show-xs-block">
                                    <select name="account" lay-filter="account" id="account" required="" lay-verify="required">
                                    </select>
                                </div>
                                <div class="layui-input-inline layui-show-xs-block">
                                    <select name="vpc" lay-filter="vpc" id="vpc" required="" lay-verify="required">
                                    </select>
                                </div>
                                <div class="layui-input-inline layui-show-xs-block">
                                    <select name="subnet" lay-filter="subnet" id="subnet" required="" lay-verify="required">
                                    </select>
                                </div>
                                <div class="layui-input-inline layui-show-xs-block">
                                    <select name="template" lay-filter="template" id="template" required="" lay-verify="required">
                                    </select>
                                </div>
                                 <div class="layui-form-item">
                                    <div class="layui-input-inline layui-show-xs-block">
                                      <button class="layui-btn" lay-submit lay-filter="deploy">部署</button>
                                    </div>
                                 </div>
                            </form>
                        </div>

                    </div>
                </div>
            </div>
        </div> 
    </body>
    <script>
      layui.use(['form', 'layer'], function() {
          let form = layui.form, layer = layui.layer, $ = layui.jquery;

          $.ajax({
                  type: 'post',
                  url: '/AwsAccount/',
                  dataType: 'json',
                  success: function(res){
                      let data = res.data;
                      $('#account').append('<option value="" selected="true" disabled="disabled">---请选择账号---</option>');
                      $.each(data, function (index, item) {
                        $('#account').append('<option value="'+item.name+'">'+item.name+'</option>')
                      });
                      form.render();
                  }
                });
          $.ajax({
                  type: 'post',
                  url: '/Template/',
                  dataType: 'json',
                  success: function(res){
                      let data = res.data;
                      $('#template').append('<option value="" selected="true" disabled="disabled">---请选择模版---</option>');
                      $.each(data, function (index, item) {
                        $('#template').append('<option value="'+item.id+'">'+item.name+'</option>')
                      });
                      form.render();
                  }
                });
          form.on('select(account)', function (data) {
              $.ajax({
                  type: 'post',
                  url: '/Vpc/',
                  data: {'account': $('#account').val()},
                  dataType: 'json',
                  success: function(res){
                      let data = res.data;
                      $('#vpc').empty();
                      $('#vpc').append('<option value="" selected="true" disabled="disabled">---请选择vpc---</option>');
                      $.each(data, function (index, item) {
                        $('#vpc').append('<option value="'+item.vpc_id+'">'+item.name+'</option>')
                      });
                      form.render();
                  }
                });
          });
          form.on('select(vpc)', function (data) {
              $.ajax({
                  type: 'post',
                  url: '/Subnet/',
                  data: {'account': $('#account').val(), 'vpc': $('#vpc').val()},
                  dataType: 'json',
                  success: function(res){
                      let data = res.data;
                      $('#subnet').empty();
                      $('#subnet').append('<option value="" selected="true" disabled="disabled">---请选择subnet---</option>');
                      $.each(data, function (index, item) {
                        $('#subnet').append('<option value="'+item.subnet_id+'">'+item.avail_zone+'</option>')
                      });
                      form.render();
                  }
              });
          });
          form.on('submit(deploy)', function (data) {
              let index1 = layer.load(1);
                $.ajax({
                    type: 'post',
                    url: '/ServerDeploy/',
                    data: data.field,
                    dataType: 'json',
                    success: function(res){
                        layer.close(index1);
                        let code = res.code;
                        if (code === 0) {
                            layer.msg("部署成功！")
                        } else {
                            layer.msg("部署失败！")
                        }
                    }
                });
              return false
          });

      });
    </script>
    <script type="text/html" id="bar">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>

    </script>
</html>